'''

@File:ihrm_emp_curd.py
@Datetime:2022/11/2 23:00
@Author:wangt
@Desc:
'''
import requests


class IhrmEmpCURD(object):

    # 1.添加员工
    @classmethod
    def add_emp(cls,header,add_data):
        url = 'http://ihrm2-test.itheima.net/api/sys/user'
        res = requests.post(url=url, headers=header, json=add_data)
        return res
    # 2.查询员工
    @classmethod
    def query_emp(cls,emp_id,header):
        url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        res = requests.get(url=url,headers=header)
        return res
    # 3.修改员工
    @classmethod
    def modify_emp(cls,emp_id,header,mod_data):
        url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        res = requests.put(url=url,headers=header,json=mod_data)
        return res

    # 4.删除员工
    @classmethod
    def delete_emp(cls,emp_id,header):
        url = "http://ihrm2-test.itheima.net/api/sys/user/" + emp_id
        res = requests.delete(url=url,headers=header)
        return res

if __name__ == '__main__':
    header = {"Content-Type": "application/json",
              "Authorization": "Bearer 9e7cb7a0-e5c1-40ef-a94e-6bdfdfab3a43"}
    # 1.测试添加员工
    # add_data = {"username": "业务猪001", "mobile": "13977734784", "workNumber": "9527"}
    # res = IhrmEmpCURD.add_emp(header,add_data)

    # 2.测试查询员工
    # emp_id = "1587829053526650880"
    # res = IhrmEmpCURD.query_emp(emp_id,header)

    # 3.测试修改员工
    # emp_id = "1587829053526650880"
    # modify_data = {"username": "天蓬元帅"}
    # res = IhrmEmpCURD.modify_emp(emp_id,header,modify_data)

    # 4.测试删除员工
    # emp_id = "1587829053526650880"
    # res = IhrmEmpCURD.delete_emp(emp_id,header)
    # print(res.json())
